﻿using System;
using System.Runtime.InteropServices;
using System.Text;

namespace OneDark.Evthing
{
    //using SetSearchW = Everything_SetSearchW;
    //using SetMatchPath = Everything_SetMatchPath;
    //using SetMatchCase = Everything_SetMatchCase;
    //using SetMatchWholeWord = Everything_SetMatchWholeWord;
    //using SetRegex = Everything_SetRegex;
    //using SetMax = Everything_SetMax;
    //using SetOffset = Everything_SetOffset;
    //using GetMatchPath = Everything_GetMatchPath;
    //using GetMatchCase = Everything_GetMatchCase;
    //using GetMatchWholeWord = Everything_GetMatchWholeWord;
    //using GetRegex = Everything_GetRegex;
    //using GetMax = Everything_GetMax;
    //using GetOffset = Everything_GetOffset;
    //using GetSearchW = Everything_GetSearchW;
    //using GetLastError = Everything_GetLastError;
    //using QueryW = Everything_QueryW;
    //using SortResultsByPath = Everything_SortResultsByPath;
    //using GetNumFileResults = Everything_GetNumFileResults;
    //using GetNumFolderResults = Everything_GetNumFolderResults;
    //using GetNumResults = Everything_GetNumResults;
    //using GetTotFileResults = Everything_GetTotFileResults;
    //using GetTotFolderResults = Everything_GetTotFolderResults;
    //using GetTotResults = Everything_GetTotResults;
    //using IsVolumeResult = Everything_IsVolumeResult;
    //using IsFolderResult = Everything_IsFolderResult;
    //using IsFileResult = Everything_IsFileResult;
    //using GetResultFullPathName = Everything_GetResultFullPathName;
    //using GetResultPath = Everything_GetResultPath;
    //using GetResultFileName = Everything_GetResultFileName;
    //using Reset = Everything_Reset;
    //using CleanUp = Everything_CleanUp;
    //using GetMajorVersion = Everything_GetMajorVersion;
    //using GetMinorVersion = Everything_GetMinorVersion;
    //using GetRevision = Everything_GetRevision;
    //using GetBuildNumber = Everything_GetBuildNumber;
    //using Exit = Everything_Exit;
    //using IsDBLoaded = Everything_IsDBLoaded;
    //using IsAdmin = Everything_IsAdmin;
    //using IsAppData = Everything_IsAppData;
    //using RebuildDB = Everything_RebuildDB;
    //using UpdateAllFolderIndexes = Everything_UpdateAllFolderIndexes;
    //using SaveDB = Everything_SaveDB;
    //using SaveRunHistory = Everything_SaveRunHistory;
    //using DeleteRunHistory = Everything_DeleteRunHistory;
    //using GetTargetMachine = Everything_GetTargetMachine;

    //using SetSort = Everything_SetSort;
    //using GetSort = Everything_GetSort;
    //using GetResultListSort = Everything_GetResultListSort;
    //using SetRequestFlags = Everything_SetRequestFlags;
    //using GetRequestFlags = Everything_GetRequestFlags;
    //using GetResultListRequestFlags = Everything_GetResultListRequestFlags;
    //using GetResultExtension = Everything_GetResultExtension;
    //using GetResultSize = Everything_GetResultSize;
    //using GetResultDateCreated = Everything_GetResultDateCreated;
    //using GetResultDateModified = Everything_GetResultDateModified;
    //using GetResultDateAccessed = Everything_GetResultDateAccessed;
    //using GetResultAttributes = Everything_GetResultAttributes;
    //using GetResultFileListFileName = Everything_GetResultFileListFileName;
    //using GetResultRunCount = Everything_GetResultRunCount;
    //using GetResultDateRun = Everything_GetResultDateRun;
    //using GetResultDateRecentlyChanged = Everything_GetResultDateRecentlyChanged;
    //using GetResultHighlightedFileName = Everything_GetResultHighlightedFileName;
    //using GetResultHighlightedPath = Everything_GetResultHighlightedPath;
    //using GetResultHighlightedFullPathAndFileName = Everything_GetResultHighlightedFullPathAndFileName;
    //using GetRunCountFromFileName = Everything_GetRunCountFromFileName;
    //using SetRunCountFromFileName = Everything_SetRunCountFromFileName;
    //using IncRunCountFromFileName = Everything_IncRunCountFromFileName;

    internal class Everything
    {
        [DllImport("Everything32.dll", CharSet = CharSet.Unicode)]
        public static extern UInt32 Everything_SetSearchW(string lpSearchString);

        [DllImport("Everything32.dll")]
        public static extern void Everything_SetMatchPath(bool bEnable);

        [DllImport("Everything32.dll")]
        public static extern void Everything_SetMatchCase(bool bEnable);

        [DllImport("Everything32.dll")]
        public static extern void Everything_SetMatchWholeWord(bool bEnable);

        [DllImport("Everything32.dll")]
        public static extern void Everything_SetRegex(bool bEnable);

        [DllImport("Everything32.dll")]
        public static extern void Everything_SetMax(UInt32 dwMax);

        [DllImport("Everything32.dll")]
        public static extern void Everything_SetOffset(UInt32 dwOffset);

        [DllImport("Everything32.dll")]
        public static extern bool Everything_GetMatchPath();

        [DllImport("Everything32.dll")]
        public static extern bool Everything_GetMatchCase();

        [DllImport("Everything32.dll")]
        public static extern bool Everything_GetMatchWholeWord();

        [DllImport("Everything32.dll")]
        public static extern bool Everything_GetRegex();

        [DllImport("Everything32.dll")]
        public static extern UInt32 Everything_GetMax();

        [DllImport("Everything32.dll")]
        public static extern UInt32 Everything_GetOffset();

        [DllImport("Everything32.dll")]
        public static extern IntPtr Everything_GetSearchW();

        [DllImport("Everything32.dll")]
        public static extern UInt32 Everything_GetLastError();

        [DllImport("Everything32.dll")]
        public static extern bool Everything_QueryW(bool bWait);

        [DllImport("Everything32.dll")]
        public static extern void Everything_SortResultsByPath();

        [DllImport("Everything32.dll")]
        public static extern UInt32 Everything_GetNumFileResults();

        [DllImport("Everything32.dll")]
        public static extern UInt32 Everything_GetNumFolderResults();

        [DllImport("Everything32.dll")]
        public static extern UInt32 Everything_GetNumResults();

        [DllImport("Everything32.dll")]
        public static extern UInt32 Everything_GetTotFileResults();

        [DllImport("Everything32.dll")]
        public static extern UInt32 Everything_GetTotFolderResults();

        [DllImport("Everything32.dll")]
        public static extern UInt32 Everything_GetTotResults();

        [DllImport("Everything32.dll")]
        public static extern bool Everything_IsVolumeResult(UInt32 nIndex);

        [DllImport("Everything32.dll")]
        public static extern bool Everything_IsFolderResult(UInt32 nIndex);

        [DllImport("Everything32.dll")]
        public static extern bool Everything_IsFileResult(UInt32 nIndex);

        [DllImport("Everything32.dll", CharSet = CharSet.Unicode)]
        public static extern void Everything_GetResultFullPathName(UInt32 nIndex, StringBuilder lpString, UInt32 nMaxCount);

        [DllImport("Everything32.dll", CharSet = CharSet.Unicode)]
        public static extern IntPtr Everything_GetResultPath(UInt32 nIndex);

        [DllImport("Everything32.dll", CharSet = CharSet.Unicode)]
        public static extern IntPtr Everything_GetResultFileName(UInt32 nIndex);

        [DllImport("Everything32.dll")]
        public static extern void Everything_Reset();

        [DllImport("Everything32.dll")]
        public static extern void Everything_CleanUp();

        [DllImport("Everything32.dll")]
        public static extern UInt32 Everything_GetMajorVersion();

        [DllImport("Everything32.dll")]
        public static extern UInt32 Everything_GetMinorVersion();

        [DllImport("Everything32.dll")]
        public static extern UInt32 Everything_GetRevision();

        [DllImport("Everything32.dll")]
        public static extern UInt32 Everything_GetBuildNumber();

        [DllImport("Everything32.dll")]
        public static extern bool Everything_Exit();

        [DllImport("Everything32.dll")]
        public static extern bool Everything_IsDBLoaded();

        [DllImport("Everything32.dll")]
        public static extern bool Everything_IsAdmin();

        [DllImport("Everything32.dll")]
        public static extern bool Everything_IsAppData();

        [DllImport("Everything32.dll")]
        public static extern bool Everything_RebuildDB();

        [DllImport("Everything32.dll")]
        public static extern bool Everything_UpdateAllFolderIndexes();

        [DllImport("Everything32.dll")]
        public static extern bool Everything_SaveDB();

        [DllImport("Everything32.dll")]
        public static extern bool Everything_SaveRunHistory();

        [DllImport("Everything32.dll")]
        public static extern bool Everything_DeleteRunHistory();

        [DllImport("Everything32.dll")]
        public static extern UInt32 Everything_GetTargetMachine();

        // Everything 1.4
        [DllImport("Everything32.dll")]
        public static extern void Everything_SetSort(UInt32 dwSortType);

        [DllImport("Everything32.dll")]
        public static extern UInt32 Everything_GetSort();

        [DllImport("Everything32.dll")]
        public static extern UInt32 Everything_GetResultListSort();

        [DllImport("Everything32.dll")]
        public static extern void Everything_SetRequestFlags(UInt32 dwRequestFlags);

        [DllImport("Everything32.dll")]
        public static extern UInt32 Everything_GetRequestFlags();

        [DllImport("Everything32.dll")]
        public static extern UInt32 Everything_GetResultListRequestFlags();

        [DllImport("Everything32.dll", CharSet = CharSet.Unicode)]
        public static extern IntPtr Everything_GetResultExtension(UInt32 nIndex);

        [DllImport("Everything32.dll")]
        public static extern bool Everything_GetResultSize(UInt32 nIndex, out long lpFileSize);

        [DllImport("Everything32.dll")]
        public static extern bool Everything_GetResultDateCreated(UInt32 nIndex, out long lpFileTime);

        [DllImport("Everything32.dll")]
        public static extern bool Everything_GetResultDateModified(UInt32 nIndex, out long lpFileTime);

        [DllImport("Everything32.dll")]
        public static extern bool Everything_GetResultDateAccessed(UInt32 nIndex, out long lpFileTime);

        [DllImport("Everything32.dll")]
        public static extern UInt32 Everything_GetResultAttributes(UInt32 nIndex);

        [DllImport("Everything32.dll", CharSet = CharSet.Unicode)]
        public static extern IntPtr Everything_GetResultFileListFileName(UInt32 nIndex);

        [DllImport("Everything32.dll")]
        public static extern UInt32 Everything_GetResultRunCount(UInt32 nIndex);

        [DllImport("Everything32.dll")]
        public static extern bool Everything_GetResultDateRun(UInt32 nIndex, out long lpFileTime);

        [DllImport("Everything32.dll")]
        public static extern bool Everything_GetResultDateRecentlyChanged(UInt32 nIndex, out long lpFileTime);

        [DllImport("Everything32.dll", CharSet = CharSet.Unicode)]
        public static extern IntPtr Everything_GetResultHighlightedFileName(UInt32 nIndex);

        [DllImport("Everything32.dll", CharSet = CharSet.Unicode)]
        public static extern IntPtr Everything_GetResultHighlightedPath(UInt32 nIndex);

        [DllImport("Everything32.dll", CharSet = CharSet.Unicode)]
        public static extern IntPtr Everything_GetResultHighlightedFullPathAndFileName(UInt32 nIndex);

        [DllImport("Everything32.dll")]
        public static extern UInt32 Everything_GetRunCountFromFileName(string lpFileName);

        [DllImport("Everything32.dll")]
        public static extern bool Everything_SetRunCountFromFileName(string lpFileName, UInt32 dwRunCount);

        [DllImport("Everything32.dll")]
        public static extern UInt32 Everything_IncRunCountFromFileName(string lpFileName);
    }

    internal enum Errorcode
    {
        OK = 0,
        MEMORY = 1,
        IPC = 2,
        REGISTERCLASSEX = 3,
        CREATEWINDOW = 4,
        CREATETHREAD = 5,
        INVALIDINDEX = 6,
        INVALIDCALL = 7
    }

    internal enum Request
    {
        FILE_NAME = 0x00000001,
        PATH = 0x00000002,
        FULL_PATH_AND_FILE_NAME = 0x00000004,
        EXTENSION = 0x00000008,
        SIZE = 0x00000010,
        DATE_CREATED = 0x00000020,
        DATE_MODIFIED = 0x00000040,
        DATE_ACCESSED = 0x00000080,
        ATTRIBUTES = 0x00000100,
        FILE_LIST_FILE_NAME = 0x00000200,
        RUN_COUNT = 0x00000400,
        DATE_RUN = 0x00000800,
        DATE_RECENTLY_CHANGED = 0x00001000,
        HIGHLIGHTED_FILE_NAME = 0x00002000,
        HIGHLIGHTED_PATH = 0x00004000,
        HIGHLIGHTED_FULL_PATH_AND_FILE_NAME = 0x00008000
    }

    internal enum Sort
    {
        NAME_ASCENDING = 1,
        NAME_DESCENDING = 2,
        PATH_ASCENDING = 3,
        PATH_DESCENDING = 4,
        SIZE_ASCENDING = 5,
        SIZE_DESCENDING = 6,
        EXTENSION_ASCENDING = 7,
        EXTENSION_DESCENDING = 8,
        TYPE_NAME_ASCENDING = 9,
        TYPE_NAME_DESCENDING = 10,
        DATE_CREATED_ASCENDING = 11,
        DATE_CREATED_DESCENDING = 12,
        DATE_MODIFIED_ASCENDING = 13,
        DATE_MODIFIED_DESCENDING = 14,
        ATTRIBUTES_ASCENDING = 15,
        ATTRIBUTES_DESCENDING = 16,
        FILE_LIST_FILENAME_ASCENDING = 17,
        FILE_LIST_FILENAME_DESCENDING = 18,
        RUN_COUNT_ASCENDING = 19,
        RUN_COUNT_DESCENDING = 20,
        DATE_RECENTLY_CHANGED_ASCENDING = 21,
        DATE_RECENTLY_CHANGED_DESCENDING = 22,
        DATE_ACCESSED_ASCENDING = 23,
        DATE_ACCESSED_DESCENDING = 24,
        DATE_RUN_ASCENDING = 25,
        DATE_RUN_DESCENDING = 26
    }

    internal enum TargetMachine
    {
        X86 = 1,
        X64 = 2,
        ARM = 3
    }
}